//
//  ByHomeHeadView.m
//  recordworktool_ios
//
//  Created by mc on 2017/11/30.
//  Copyright © 2017年 ZhangZhanbin. All rights reserved.
//

#import "ByHomeHeadView.h"

#import "ByRecordVC.h"

@implementation ByHomeHeadView

- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
        CGFloat height = 0;
        if (Device_Is_iPhoneX) {
            height = 88;
        }else{
            height = 64;
        }
        height = height + 10;
        
        UIImageView *backgroundView = [[UIImageView alloc] initWithFrame:self.bounds];
        [self addSubview:backgroundView];
        backgroundView.image = [UIImage imageNamed:@"首页背景"];
        
        UILabel *titleLabel = [[UILabel alloc] init];
        [self addSubview:titleLabel];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self).offset(0);
            make.top.equalTo(self).offset(height - 40);
            make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 40, 30));
        }];
        titleLabel.text = @"今日记账";
        titleLabel.textColor = [UIColor whiteColor];
        titleLabel.textAlignment = NSTextAlignmentCenter;
        titleLabel.font = FONT(22);
        
        
        UIView *view = [[UIView alloc] init];
        [self addSubview:view];
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).offset(height + 20);
            make.left.equalTo(self).offset(0);
            make.right.equalTo(self).offset(0);
            Device_Is_iPhoneX ? make.height.mas_equalTo(@(280 - 80 - height - 20 + (88 - 64))) : make.height.mas_equalTo(@(280 - 80 - height - 20));
            
        }];
        
        CGFloat width = (SCREEN_WIDTH - 2) / 3.0;
        
        height =  280 - 80 - height - 20;
        if (Device_Is_iPhoneX) {
            height = height + 88 - 64;
        }
        UILabel *line = [[UILabel alloc] init];
        [view addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(view).offset(width);
            make.top.equalTo(view).offset(0);
            make.size.mas_equalTo(CGSizeMake(1, height));
        }];
        line.backgroundColor = [UIColor whiteColor];
        
        UILabel *line2 = [[UILabel alloc] init];
        [view addSubview:line2];
        [line2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(view).offset(-width);
            make.top.equalTo(view).offset(0);
            make.size.mas_equalTo(CGSizeMake(1, height));
        }];
        line2.backgroundColor = [UIColor whiteColor];
        
        
        
        
        UIView *recoredView = [[UIView alloc] init];
        [self addSubview:recoredView];
        [recoredView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self).offset(-20);
            make.centerX.equalTo(self).offset(0);
            make.size.mas_equalTo(CGSizeMake(160, 35));
        }];
        recoredView.backgroundColor = [UIColor whiteColor];
        recoredView.layer.cornerRadius = 8;
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(recoredAction:)];
        [recoredView addGestureRecognizer:tap];
        
        UILabel *recoredLabel = [[UILabel alloc] init];
        [recoredView addSubview:recoredLabel];
        [recoredLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(recoredView.mas_centerX).offset(20);
            make.centerY.equalTo(recoredView.mas_centerY).offset(0);
            make.size.mas_equalTo(CGSizeMake(60, 20));
        }];
        recoredLabel.text = @"记一笔";
        recoredLabel.font = FONT(18);
        recoredLabel.textColor = BY_THEME_COLOR;
        
        UIImageView *smallView = [[UIImageView alloc] init];
        [recoredView addSubview:smallView];
        [smallView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(recoredLabel.mas_left).offset(-10);
            make.centerY.equalTo(recoredView).offset(0);
            make.size.mas_equalTo(CGSizeMake(20, 20));
        }];
        smallView.image = [UIImage imageNamed:@"jiyibi"];
        smallView.userInteractionEnabled = YES;
        
        
        
        UILabel *stateLabel = [[UILabel alloc] init];
        [self addSubview:stateLabel];
        [stateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(recoredView.mas_right).offset(10);
            make.right.equalTo(self).offset(-10);
            make.centerY.equalTo(recoredView.mas_centerY).offset(0);
            make.height.mas_equalTo(@15);
        }];
        stateLabel.font = FONT(14);
        stateLabel.textColor = [UIColor redColor];
        self.stateLabel = stateLabel;
        
        
        ByHomeTitleValueView *leftView = [[ByHomeTitleValueView alloc] init];
        [view addSubview:leftView];
        [leftView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(view).offset(0);
            make.top.equalTo(view).offset(0);
            make.size.mas_equalTo(CGSizeMake(width, height));
        }];
        leftView.titleLabel.text = @"上班(小时)";
        ByHomeTitleValueView *rightView = [[ByHomeTitleValueView alloc] init];
        [view addSubview:rightView];
        [rightView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(view).offset(0);
            make.top.equalTo(view).offset(0);
            make.size.mas_equalTo(CGSizeMake(width, height));
        }];
        rightView.titleLabel.text = @"加班(小时)";
        
        ByHomeTitleValueView *centerView = [[ByHomeTitleValueView alloc] init];
        [view addSubview:centerView];
        [centerView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(view).offset(0);
            make.top.equalTo(view).offset(0);
            make.size.mas_equalTo(CGSizeMake(width, height));
        }];
        centerView.titleLabel.text = @"收入(元)";
        if (BY_USER.isWorker.integerValue == 0) {
            leftView.titleLabel.text = @"借支";
            rightView.titleLabel.text = @"工人工资支出";
            centerView.titleLabel.text = @"结算";
        }
        
        self.leftView = leftView;
        self.centerView = centerView;
        self.rightView = rightView;
    }
    return self;
}

- (void)recoredAction:(UITapGestureRecognizer *)tap{
    self.recorded();
}

@end
